// phalanx count_if.hpp.cu header file

// Copyright (c) 2010 - 2011 Kohei Takahashi (Flast).
// Distributed under the MIT license. for more detail see COPYING.

// Redefinition C++03 count if algorithm

#ifndef IG_PHALANX_ALGORITHM_COUNT_IF_HPP_CU_ONCE_
#define IG_PHALANX_ALGORITHM_COUNT_IF_HPP_CU_ONCE_

#include <phalanx/config.hpp.cu>

#include <cstddef>

#include <phalanx/utility/begin_end.hpp.cu>

namespace phalanx
{

template < typename InputIterator, typename Predicate >
PHALANX_CONFIG_DEFAULT_FUNCTION( false )
::std::ptrdiff_t
count_if( InputIterator first, const InputIterator last, Predicate pred )
{
    ::std::ptrdiff_t ret = 0;
    for ( ; first != last; ++first )
    { ret += static_cast< bool >( pred( *first ) ); }
    return ret;
}

template < typename Container, typename Predicate >
PHALANX_CONFIG_DEFAULT_FUNCTION( false )
::std::ptrdiff_t
count_if( Container &cont, Predicate pred )
{ return count_if( begin( cont ), end( cont ), pred ); }

template < typename Container, typename Predicate >
PHALANX_CONFIG_DEFAULT_FUNCTION( false )
::std::ptrdiff_t
count_if( const Container &cont, Predicate pred )
{ return count_if( begin( cont ), end( cont ), pred ); }

} // namespace phalanx

#endif // IG_PHALANX_ALGORITHM_COUNT_IF_HPP_CU_ONCE_

